#!/bin/bash
#SBATCH --spread-job
# Copyright (c) 2023 Presto Labs Pte. Ltd.

set -e
source /remote/iosg/home-8/bot-hft/miniconda3/etc/profile.d/conda.sh
conda activate /remote/iosg/home-8/bot-hft/miniconda3/envs/coin2_motion_env_migration

cd /remote/iosg/jenkins-2/bot-hft/jenkins/workspace/coin2_feed_latency_stats/coin/python

# set env
source ${CONDA_PREFIX}/opt/hyper/bin/envsetup.sh
source ${CONDA_PREFIX}/opt/papyrus/bin/envsetup.sh
REPO_ROOT="$(git rev-parse --show-toplevel)"
export BATCH_INSTALL_ROOT=${BATCH_INSTALL_ROOT:-"${REPO_ROOT}/external"}

NUM_PARALLEL="$((${SLURM_NTASKS} + 30))"
parallel -j "${NUM_PARALLEL}" --delay 0.01 <<EOF
{% for machine in settings.keys() -%}
{% for mea in settings[machine].keys() -%}
{% for recipe in settings[machine][mea].keys() -%}
{% for group in settings[machine][mea][recipe].keys() -%}
{% for worker in settings[machine][mea][recipe][group]["worker"] -%}
srun -N1 -n1 -l --mem-per-cpu=2G --exclusive ./pyrunner coin/support/feed_tool/feed_stats/app/feed_stats_motion/feed_stats_single_process_runner.py --trading_date="{{start_time}}" --duration="{{duration}}" --machine="{{machine}}" --mea="{{mea}}" --recipe="{{recipe}}" --group="{{group}}" --worker={{worker}} --run_for_raw={{settings[machine][mea][recipe][group]["raw"]}} --interval="{{interval}}" --latency_stat_only=True
{% endfor -%}
{% endfor -%}
{% endfor -%}
{% endfor -%}
{% endfor -%}
EOF

